package com.design.mode.single;

import java.util.ArrayList;

/**
 * @Date 2023/3/29 15:17:18
 * @Author luopeng
 */
public class SingletonPatternDemo {
    public static void main(String[] args) {
        // 饿汉式
        /*for (int i = 0; i < 10; i++) {
            new Thread(() -> System.out.println(Thread.currentThread().getName() + SingleObject.getSingleObject().toString()), "饿汉式测试线程-" + i + "\t").start();
        }*/
        // 懒汉式线程不安全
        /*for (int i = 0; i < 100; i++) {
            new Thread(() -> System.out.println(Thread.currentThread().getName() + SingleObjectLazy.getSingleObject().toString()), "懒汉式测试线程-" + i + "\t").start();
        }*/
        // 懒汉式线程安全
        /*for (int i = 0; i < 100; i++) {
            new Thread(() -> System.out.println(Thread.currentThread().getName() + SingleObjectLazy.getSingleObjectSecurity().toString()), "懒汉式线程安全测试线程-" + i + "\t").start();
        }*/
        // 双检锁模式
       /* for (int i = 0; i < 100; i++) {
            new Thread(() -> System.out.println(Thread.currentThread().getName() + SingleObjectDoubleCheckedLocking.getSingleObject().toString()), "双检锁模式测试线程-" + i + "\t").start();
        }*/
    }
}
